<?php 

	use \FileManager;
  
/**
 * PrintController.
 * 
 * This is the example of the simple controller that could be used for the documents printing 
 * 
 * @author Sysprog <sysprog@martis-ua.com> 
 * @link http://www.seo-design.kiev.ua/ 
 * @copyright Copyright &copy; 2014 
 * @license http://www.seo-design.ua/license/  
 * @version 1.0.0.1 $ 
 */ 
  
	class PrintController extends Controller { 

    /** 
     *  Printing of the order from the  CArrayDataProvider() 
     */ 
		public function actionIndex() {   

      // Yii::import( 'application.modules.your_module.models.*' );  

      // The object of the documents that do you want to print 
      // $doc = ( new YourDocument() )->findByPk( (int) Yii::app()->request->getParam( 'id' ) ); 
      
      $doc = array ( 'id' => 'docId', 
                     'code' => 'code of doc', 
                     'create_time' => '2014-06-16 13:37', 
                     'name' => 'SEO Design UAs', 
                     'phone' => '+380 77 777 7777', 
                     'address' => 'Poshtova Plocha 1, Kiev, Ukraine', 
                     'products' => array( 
                        array( 'code' => 'SEO_hits', 'title' => 'Fixed SEO hits', 'quantity' => 10, 'price' => 0.2 ),         // 10 hits per host 
                        array( 'code' => 'SEO_hosts', 'title' => 'Fixed SEO hosts', 'quantity' => 30, 'price' => 8.0 ),       // 30 hosts per site or page 
                        array( 'code' => 'SEO_CONV', 'title' => 'SEO conversion', 'quantity' => 1, 'price' => 200.0 ),        // price for conversion 
                        array( 'code' => 'SEO_SITE', 'title' => 'Complete Web Site', 'quantity' => 1, 'price' => 200000.0 ),  // price for web site 
                      )  
                   ); 

      $toPrint = array(  ); 

      $toPrint['id'] = $doc['id']; 
      $toPrint['order_id'] = $doc['code']; 
      $toPrint['order_date'] = date( "d F Y", $doc['create_time']); 
      $toPrint['client_details'] = $doc['name'].'\r\n'.$doc['phone'].'\r\n'.$doc['address']; 

      $num = 1;  $sum = 0.0; 
      foreach ( $doc['products'] as $product ) { 

          $product_row = array(); 

          $product_row[$num]['o_goods_number'] = $num; 
          $product_row[$num]['o_goods_code'] = $product["code"]; 
          $product_row[$num]['o_goods_title'] = $product["title"]; 
          $product_row[$num]['o_goods_amount'] = $product["quantity"]; 
          $product_row[$num]['o_goods_price'] = $product["price"]; 
          $product_row[$num]['o_goods_total'] = $product["quantity"] * $product["price"]; 

          $sum += $product["quantity"] * $product["price"]; 

          $num++; 
      } 

      $toPrint['goods'] = $product_row; 

      $toPrint['items_count'] = count( $doc['products'] ); 
      $toPrint['total_amount'] = $sum; 

      $file = new FileManager(); 

      $content = $file->getDocsFile( new CArrayDataProvider( $toPrint, array() ), '/files/bill.txt' ); 

		} 

	}

?>